﻿using System.Linq;
using Csla.Data;

namespace Accounting.Library
{
    public class TaiKhoanService
    {
        /// <summary>
        /// Lay id cua tai khoan
        /// </summary>
        /// <param name="ctx">Data access context</param>
        /// <param name="maTK">Ma tai khoan</param>
        /// <returns>Id cua tai khoan</returns>
        public static int LayIdCuaTaiKhoan(ContextManager<Accounting.DataAccess.AccountingDataContext> ctx, string maTK) 
        {
            try
            {
                Accounting.DataAccess.DM_TaiKhoan taiKhoan = (from p in ctx.DataContext.DM_TaiKhoans
                                                              where (p.Ma == maTK)
                                                              select p).Single();

                return taiKhoan.Khoa;
            }
            catch 
            {
                return 0;
            }
        }

        /// <summary>
        /// Lay id cua tai khoan
        /// </summary>
        /// <param name="maTK">Ma tai khoan</param>
        /// <returns>Id cua tai khoan</returns>
        public static int LayIdCuaTaiKhoan( string maTK)
        {
            return csla4skeleton.DataAcess.ExecuteSQLService.GetTaiKhoanId(maTK);
        }
    }
}
